<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use DB;

class UserVipController extends Controller
{
       // 检测用户是否登录，无登录跳转到登录页面
    public function __construct()
    {
       $this->middleware('auth');
    }
    public function index(){

    	//获取会员充值订单
    	$user = DB::table('order_vip')->OrderBy('id','desc')->get();

    	return view('user.viporder',compact('user'));
    }

    //充值会员设置
    public function create(){

    	 $uservip = DB::table('vipset')->find(1);

    	return view('user.viporderset',compact('uservip'));
    }


    //会员规则设置
    public function store(Request $request){

        //数据集合
        $data = $request->only(['title','content','price','created_at']);

        //设置时间
        $data['created_at'] = date('Y-m-d H:i:s');

        //设置金额
        $data['price'] = $request->money;

        if(in_array(null, $data))
        {

                return '请检查表格是否完整';exit;
        }

        //数据入库
        $status = DB::table('vipset')->insert($data);

        //判断是否入库成功
        if($status){

            return back();
        }
    }

    //会员设置更新
    public function update($id,Request $request){

        //数据集合
        $data = $request->only(['title','content','price','created_at']);

        //设置时间
        $data['created_at'] = date('Y-m-d H:i:s');

        //设置金额
        $data['price'] = $request->money;

        if(in_array(null, $data))
        {

                return '请检查表格是否完整';exit;
        }
        
        //数据更新
        $status = DB::table('vipset')->where('id',$id)->update($data);

        //判断是否修改成功
        if($status){

            return back();
        }
    }
}
